home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 103 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.9 KB  |  63 lines

  1. Newsgroups: comp.std.c++
  2. Path: cs.mu.OZ.AU!bounce-back
  3. From: psk3@pge.com (Phillip Knight)
  4. Subject: base class operator hiding
  5. Message-ID: <4e1in5$5en@news02.comp.pge.com>
  6. Originator: fjh@munta.cs.mu.OZ.AU
  7. Sender: news@cs.mu.OZ.AU (CS-Usenet)
  8. Organization: Pacific Gas and Electric
  9. X-Newsreader: WinVN 0.99.6
  10. References: <01BAE8B0.C408A920@dino.int.com>
  11. X-Original-Date: 23 Jan 1996 02: 55:33 GMT
  12. Date: Tue, 23 Jan 1996 03:34:26 GMT
  13. Approved: fjh@cs.mu.oz.au
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBFAgUBMQRXgeEDnX0m9pzZAQEtmQF/Tp7W/6Q8RCLWJyQYxYNsF6eyJnYoEWc4
  16.     r9tBAggGClAdTwHj++O3SPvW9M38RwVJ
  17.     =0kBG
  18.  
  19. This may or may not be appropriate for this group, but here goes:
  20.  
  21. Given this code snippet:
  22.  
  23.      #include <strstream.h>
  24.      
  25.         class foo {};
  26.  
  27.      class ologstream : public ostream {
  28.         public:
  29.             ologstream() {}
  30.            virtual ~ologstream() {};
  31.                                   
  32.         ologstream& operator<< (foo &bar)
  33.                    { return *this; }  // do nothing
  34.      };
  35.  
  36.  
  37.      int main(int, char **)
  38.      {
  39.         ologstream out;
  40.  
  41.         out << "Test one.";
  42.            return 1;
  43.        }
  44.  
  45. The program does not compile, giving an error where the char * is acted
  46. on by ostream/ologstream operators.  The presence of an operator<<
  47. (overloaded or otherwise) in the dervided class consequently hides the base
  48. class operators which are public.  My question is; is this a bug in the
  49. language or in the implementation, or is it just me?  I have attempted this
  50. code fragment on several compilers with the same results, which makes me
  51. wonder...  
  52. This fragment, btw, is for illustration, not as an example of good coding 
  53. or design.
  54.  
  55. Thanks for your time and consideration,
  56. Phil Knight
  57. psk3@pge.com
  58.  
  59. ---
  60. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  61.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  62.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  63.